package com.amgl.amupush.application;

import android.app.Application;
import android.util.Log;

import com.amgl.amupush.utils.AmuUtils;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

import cn.jpush.android.api.JPushInterface;
import timber.log.Timber;

/**
 * Created by amglh on 2016/8/5.
 */
public class AmuApplication extends Application {
    private static AmuApplication instance = null;

    public static AmuApplication getInstance() {
        return instance;
    }

    private RefWatcher refWatcher;

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d("AmuApplication", "onCreate");
        instance = this;

        String processName = AmuUtils.getAppName(this);

        //防止远程Service调用导致App初始化2次
        if (processName != null && processName.equalsIgnoreCase(this.getPackageName())) {
            initApp();
        }
    }

    /**
     * 初始化
     */
    private void initApp() {
        Log.d("AmuApplication", "init");
        Timber.plant(new Timber.DebugTree());
        refWatcher = LeakCanary.install(this);
        initJPush();
    }

    /**
     * 极光推送
     */
    private void initJPush() {
        Timber.d("init JPush");
        JPushInterface.setDebugMode(false);
        JPushInterface.init(this);
        JPushInterface.setAlias(this, "amu", null);
    }

    public RefWatcher getRefWatcher() {
        return refWatcher;
    }
}
